#include "process.h"
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#define STYLE '='
#define NUM 101

void process_v1()
{
    char buffer[NUM];
    memset(buffer, 0, sizeof(buffer));
    const char* lable = "|/-\\";
    int len = strlen(lable);

    for(int i = 0; i < NUM; i++)
    {
        printf("[%-100s][%d%%][%c]\r", buffer, i, lable[i%len]);
        fflush(stdout);
        buffer[i] = STYLE;
        usleep(50000);
    }
    printf("\n");
}


void process_fflush(double current, double total)
{

    char buffer[NUM];
    memset(buffer, 0, sizeof(buffer));
    static const char* lable = "|/-\\";
    static int k = 0;
    k = (k + 1) % 4;
    int len = strlen(lable);
    double rate = current * 100 / total;

    for(int i = 0; i < rate; i++)
    {
        buffer[i] = STYLE;
    }
    printf("[%-100s][%.1f%%][%c]\r", buffer, rate, lable[k]);
    fflush(stdout);
}
